<?php

namespace App\Common\Middleware;

use App\Common\Util\Response;
use App\Common\Util\TP;
use App\Install\Service\InitService;
use App\Request;

/**
 * 初始化检测
 */
class InitCheckMiddleware
{
    public function handle(Request $request, \Closure $next): \think\Response
    {
        if (!InitService::isInitComplete() && php_sapi_name() != 'cli' && TP::request()->url() != '/install') {
            return Response::redirect(TP::route()->getCurrentUrl()->getDomain() . "/install");
        }

        return $next($request);
    }
}